import 'dart:convert';

///
/// 发送信息模型
///
class XMessage {
  final String role;
  final String content;
  final String? name;

  XMessage({
    required this.role,
    required this.content,
    this.name,
  });

  factory XMessage.fromJson(String source) {
    final map = json.decode(source) as Map<String, dynamic>;

    return XMessage(
      content: map['content'] as String,
      role: map['role'] as String,
      name: map['name'] as String?,
    );
  }

  Map<String, String?> toMap() => ({
        'content': content,
        'role': role,
        'name': name,
      });

  @override
  String toString() => 'Message(content: $content, role: $role, name: $name)';
}
